/**
 * 
 */
package nl.boektrust.btsoep.shared.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.googlecode.objectify.annotation.Serialized;

/**
 * @author rao3
 *
 */
@Entity
public class BinaryAsset implements Serializable,IsSerializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */

	@Id Long id;

	private long recordReference; // onix; ut
	private BlobKey blobKey; // onix; ut
	private String originalUrl; // onix; ut
	private ImageReferenceTypeCode imageReferenceTypeCode;
	private Date modificationDate;
	private Date firstModificationDate;
	

	
	
	/**
	 * @param title
	 */
	public BinaryAsset(String url) {
		super();
		//System.err.println("Constructor title called");
		this.recordReference = 0;
		this.blobKey = null;
		this.originalUrl = url;
		this.imageReferenceTypeCode = ImageReferenceTypeCode.UNDEFINED;
	}
	
	/**
	 * @return the url
	 */
	public String getOriginalUrl() {
		return originalUrl;
	}

	/**
	 * @param url the url to set
	 */
	public void setOriginalUrl(String originalUrl) {
		this.originalUrl = originalUrl;
	}

	public BinaryAsset() {
		this("");
	}
	
	/**
	 * @return the recordReference
	 */
	public long getRecordReference() {
		return recordReference;
	}

	/**
	 * @param recordReference the recordReference to set
	 */
	public void setRecordReference(long recordReference) {
		this.recordReference = recordReference;
	}

	/**
	 * @return the blobKey
	 */
	public BlobKey getBlobKey() {
		return blobKey;
	}

	/**
	 * @param blobKey the blobKey to set
	 */
	public void setBlobKey(BlobKey blobKey) {
		this.blobKey = blobKey;
	}

	/**
	 * @return the imageReferenceTypeCode
	 */
	public ImageReferenceTypeCode getImageReferenceTypeCode() {
		return imageReferenceTypeCode;
	}

	/**
	 * @param imageReferenceTypeCode the imageReferenceTypeCode to set
	 */
	public void setImageReferenceTypeCode(
			ImageReferenceTypeCode imageReferenceTypeCode) {
		this.imageReferenceTypeCode = imageReferenceTypeCode;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the modificationDate
	 */
	public Date getModificationDate() {
		return modificationDate;
	}

	/**
	 * @param modificationDate the modificationDate to set
	 */
	public void setModificationDate(Date modificationDate) {
		this.modificationDate = modificationDate;
	}

	/**
	 * @return the firstModificationDate
	 */
	public Date getFirstModificationDate() {
		return firstModificationDate;
	}

	/**
	 * @param firstModificationDate the firstModificationDate to set
	 */
	public void setFirstModificationDate(Date firstModificationDate) {
		this.firstModificationDate = firstModificationDate;
	}
	
	
	
	@javax.persistence.PrePersist
	@javax.persistence.PreUpdate
	public void updateCurrentDate () {
		if (this.firstModificationDate == null) {
			this.setFirstModificationDate(new Date());
		}
		this.setModificationDate(new Date());
	}
	

}
